package com.ptu.spzx.manager.controller;

import com.ptu.spzx.manager.service.SysRoleMenuService;
import com.ptu.spzx.model.dto.system.AssginMenuDto;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.List;
@RestController
@RequestMapping(value = "/ac/system/sysRoleMenu")
public class SysRoleMenuController {
    @Autowired
    private SysRoleMenuService sysRoleMenuService;
    //查询所有菜单和查询角色分配过的菜单Id列表
    @GetMapping("/findSysRoleMenuByRoleId/{roleId}")
    @PreAuthorize("@permissionService.hasPermission('system:sysRoleMenu:findSysRoleMenuByRoleId')")
    public Result findSysRoleMenuByRoleId(@PathVariable("roleId") Long roleId){
        Map<String,Object> map = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);
        return Result.build(map, ResultCodeEnum.SUCCESS);
    }
    //保存角色分配的菜单数据
    @PostMapping("/doAssign")
    @PreAuthorize("@permissionService.hasPermission('system:sysRoleMenu:doAssign')")
    public Result doAssign(@RequestBody AssginMenuDto assginMenuDto){
      sysRoleMenuService.doAssign(assginMenuDto);
      return Result.build(null,ResultCodeEnum.SUCCESS);
    }



}
